package com.ujiuye.servlet;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ujiuye.service.StudentService;
import com.ujiuye.utils.PageTools;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * jdbc 1
 * c3p0 2
 * DbUtils 1
 * JSTL  2
 * jackson  3
 *
 * servlet + jsp
 *
 */
@WebServlet("/studentServlet")
public class StudentServlet extends BaseServlet {

    private StudentService studentService = new StudentService();
    /**
     * 分页模糊
     * @param req
     * @param resp
     */
    public void dimQuery(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //接收参数  currentPage  pageSize  search
        String currentPage = req.getParameter("currentPage");
        String pageSize = req.getParameter("pageSize");
        String search = req.getParameter("search");

        //调用service方法
        PageTools pt = studentService.dimQuery(currentPage,pageSize,search);

        //先转json
        String json = new ObjectMapper().writeValueAsString(pt);
        resp.getWriter().print(json);


    }

    /**
     * 注册
     * @param req
     * @param resp
     */
    public void registerStudent(HttpServletRequest req,HttpServletResponse resp) {
        String sname = req.getParameter("sname");
        String date = req.getParameter("date");
        String hobby = req.getParameter("hobby");
        String sex = req.getParameter("sex");
        System.out.println(sname + "..." + date +  "..." + sex + "..." + hobby);


    }
}
